package hust.game.screen;

import hust.game.main.MyGame;

import com.badlogic.gdx.Gdx;
import com.badlogic.gdx.Input.Keys;
import com.badlogic.gdx.InputMultiplexer;
import com.badlogic.gdx.Screen;
import com.badlogic.gdx.graphics.GL10;
import com.badlogic.gdx.scenes.scene2d.Stage;

public abstract class AbstractScreen implements Screen {
	protected MyGame game;
	private Stage backStage;
	protected InputMultiplexer inputProcessor;

	public AbstractScreen() {
		game = MyGame.getInstance();
		backStage = new Stage() {
			public boolean keyDown(int keyCode) {
				if (keyCode == Keys.ESCAPE || keyCode == Keys.BACK) {
					onBackKeyPress();
					return true;
				}
				return super.keyDown(keyCode);
			}
		};
		inputProcessor = new InputMultiplexer();
	}

	protected void onBackKeyPress() {
		
	}

	@Override
	public void render(float delta) {
		Gdx.gl.glClearColor(1, 1, 1, 1);
		Gdx.gl.glClear(GL10.GL_COLOR_BUFFER_BIT);
		if(getStage()!=null){
			getStage().act(delta);
			getStage().draw();
		}
	}

	@Override
	public void resize(int width, int height) {

	}

	@Override
	public void show() {
		inputProcessor.clear();
		inputProcessor.addProcessor(backStage);
		Stage st = getStage();
		if (st != null) {
			inputProcessor.addProcessor(st);
		}
		Gdx.input.setInputProcessor(inputProcessor);
		Gdx.input.setCatchBackKey(true);
	}

	@Override
	public void hide() {

	}

	@Override
	public void pause() {

	}

	@Override
	public void resume() {
		// TODO Auto-generated method stub

	}

	@Override
	public void dispose() {
		// TODO Auto-generated method stub

	}

	public abstract Stage getStage();
	
}
